package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.DrugPurchase;
import com.ruoyi.project.drug.service.IDrugPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/drug/purchase")
public class DrugPurchaseController extends BaseController {
    @Autowired
    private IDrugPurchaseService drugPurchaseService;

    /**
     * 查询【请填写功能名称】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugPurchase drugPurchase)
    {
        startPage();
        List<DrugPurchase> list = drugPurchaseService.selectDrugPurchaseList(drugPurchase);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DrugPurchase drugPurchase)
    {
        List<DrugPurchase> list = drugPurchaseService.selectDrugPurchaseList(drugPurchase);
        ExcelUtil<DrugPurchase> util = new ExcelUtil<DrugPurchase>(DrugPurchase.class);
        return util.exportExcel(list, "purchase");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:query')")
    @GetMapping(value = "/{purId}")
    public AjaxResult getInfo(@PathVariable("purId") String purId)
    {
        return AjaxResult.success(drugPurchaseService.selectDrugPurchaseById(purId));
    }

    /**
     * 新增【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugPurchase drugPurchase)
    {
        return toAjax(drugPurchaseService.insertDrugPurchase(drugPurchase));
    }

    /**
     * 修改【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugPurchase drugPurchase)
    {
        return toAjax(drugPurchaseService.updateDrugPurchase(drugPurchase));
    }

    /**
     * 删除【请填写功能名称】
     */
    //@PreAuthorize("@ss.hasPermi('system:purchase:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purIds}")
    public AjaxResult remove(@PathVariable String[] purIds)
    {
        return toAjax(drugPurchaseService.deleteDrugPurchaseByIds(purIds));
    }
}
